#include <bits/stdc++.h>

#define ll long long
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
const int INF = 1e9;
using namespace std;
/*思考区
找到最小满足要求的子序列长度，若不满足条件，输出0
*/
void solve()
{
    int n = 0, x;
    int ans = INF;
    int has[10001] = {0};
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> x;
        has[x]++;
        if (has[0] == 3 && has[1] == 1 && has[2] == 2 && has[3] == 1 && has[5] == 1)
        {
            ans = min(ans, i);
        }
    }
    if (ans == INF)
    {
        cout << 0 << endl;
        return;
    }
    cout << ans << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t = 0;
    cin >> t;
    while (t--)
        solve();
    return 0;
}